package com.codedancer.campus.manager.mq.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MqSendMessageProducer {

    @Autowired
    private AmqpTemplate amqpTemplate;
    // 系统消息key
    private static final String SYSTEM_MESSAGE = "system.message";

    /**
     * 发送系统消息
     *
     * @param param 发送参数
     */
    public void sendSystemMessage(String param) {
        log.info("开始将系统消息投递到消息队列中");
        try {
            amqpTemplate.convertAndSend(SYSTEM_MESSAGE, param);
            log.info("系统消息投递成功");
        } catch (Exception e) {
            log.info("系统消息投递失败");
            // TODO 做个兜底
        }
    }
}
